﻿using System;
using System.Reflection;

namespace Phoenix.Framework.Extensions
{
    public static class MemberExtensions
    {
         public static object GetValue(this MemberInfo memberInfo, object instance)
         {
             var propertyInfo = memberInfo as PropertyInfo;
             if (propertyInfo != null)
                 return propertyInfo.GetValue(instance, null);

             var fieldInfo = memberInfo as FieldInfo;
             if (fieldInfo != null)
                 return fieldInfo.GetValue(instance);

             const string message = "Member of type {0} is not supported by Phoenix yet, please report this as an issue";
             throw new NotSupportedException(string.Format(message, memberInfo.GetType()));
         }
    }
}